<template>
  <div>
    <el-form ref="dataForm" v-model="query" class="form" :rules="rules">
      <!-- <el-form-item prop="ck_007_sys_setting_sp4_21">
        <el-checkbox v-model="query.ck_007_sys_setting_sp4_21">启用电子签章</el-checkbox>
      </el-form-item> -->
      <el-form-item prop="pbxURL">
        <span style="font-size: 14px; color: #606266;">本地PBX代理 </span><el-input v-model="query.pbxURL" placeholder="请输入IP:Port" style="width: 400px;" />
        <!-- <el-checkbox v-model="query.ck_007_sys_setting_sp5_15">启用云呼叫</el-checkbox> -->
      </el-form-item>

      <el-form-item prop="ck_007_sys_setting_1_22">
        <el-checkbox v-model="query.ck_007_sys_setting_1_22" title="总公司市价无需审核 第一级机构的管理员无需审核 数据权限为不限的无需审核">设置价格后需要上级审核（区域价、特别价）</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_1_25">
        <el-checkbox v-model="query.ck_007_sys_setting_1_25">还瓶时需要扫瓶</el-checkbox>
      </el-form-item>
      <el-form-item prop="maxFloor">
        <span style="font-size: 14px; color: #606266;">最高楼层:</span>
        <el-input-number v-model="query.maxFloor" size="mini" disabled controls-position="right" :min="0" />
        &nbsp;&nbsp;&nbsp;
        <span style="font-size: 14px; color: #606266;">上楼费基数:</span>
        <el-input-number v-model="query.fee1" size="mini" disabled controls-position="right" :min="0" />
      </el-form-item>
      <!-- <el-form-item prop="fee1" label="上楼费基数:">
        <el-input-number v-model="query.fee1" size="mini" disabled controls-position="right" :min="0" />
      </el-form-item> -->
      <el-form-item prop="ck_007_sys_setting_1_28">
        <el-checkbox v-model="query.ck_007_sys_setting_1_28">启用实名制订气</el-checkbox>
      </el-form-item>

      <el-form-item prop="ck_007_sys_setting_2_16">
        <el-checkbox v-model="query.ck_007_sys_setting_2_16">回收时间可修改</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_2_24">
        <el-checkbox v-model="query.ck_007_sys_setting_2_24">允许特价定义服务费</el-checkbox>
      </el-form-item>
      <el-form-item prop="depAuditChannel">
        <span style="font-size: 14px; color: #606266;">押金自动审核生效渠道:</span>
        <el-select v-model="query.depAuditChannel" multiple placeholder="请选择" style="width: 25%;">
          <el-option
            v-for="item in channelOptions"
            :key="item.value"
            :label="item.desc"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item v-if="userInfo.userName === '007'" prop="ck_007_sys_setting_2_26">
        <el-checkbox v-model="query.ck_007_sys_setting_2_26">启用新版支付</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_3_8">
        <el-checkbox v-model="query.ck_007_sys_setting_3_8">兑换订单不允许退货</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_3_14">
        <el-checkbox v-model="query.ck_007_sys_setting_3_14">启用支付宝小程序</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_3_18">
        <el-checkbox v-model="query.ck_007_sys_setting_3_18">话务下单/微信审核时允许下达安检任务单</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_3_19">
        <el-checkbox v-model="query.ck_007_sys_setting_3_19">启用新版微信商城</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_3_10">
        <el-checkbox v-model="query.ck_007_sys_setting_3_10">客户地址归属机构随订单签收机构更新</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_sp6_9">
        <el-checkbox v-model="query.ck_007_sys_setting_sp6_9">回执信息不可编辑</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_sp6_18">
        <el-checkbox v-model="query.ck_007_sys_setting_sp6_18">押金回执附件信息不允许为空</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_3_31">
        <el-checkbox v-model="query.ck_007_sys_setting_3_31">安检不合格不再下发安检任务</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_sp4_1">
        <el-checkbox v-model="query.ck_007_sys_setting_sp4_1">随单安检自动审核</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_sp4_2">
        <el-checkbox v-model="query.ck_007_sys_setting_sp4_2">定期安检自动审核</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_sp4_22">
        <el-checkbox v-model="query.ck_007_sys_setting_sp4_22">异常订单处理退款</el-checkbox>
      </el-form-item>
      <el-form-item prop="">
        <div style="font-size: 14px; color: #606266;">线上审核与线下稽查权重比例</div>
        <span style="font-size: 14px; color: #606266;">线上审核: </span><el-input v-model.number="query.onlineAudit" oninput="if(!/^[0-9]+$/.test(value)) value=value.replace(/\D/g,'');if(value>100)value=100;if(value<0)value=null" placeholder="" style="width: 80px;"><template slot="suffix">%</template></el-input>
        <span style="font-size: 14px; color: #606266;">线下检查: </span><el-input v-model.number="query.offlineAudit" oninput="if(!/^[0-9]+$/.test(value)) value=value.replace(/\D/g,'');if(value>100)value=100;if(value<0)value=null" placeholder="" style="width: 80px;"><template slot="suffix">%</template></el-input>
        <!-- <el-checkbox v-model="query.ck_007_sys_setting_sp5_15">启用云呼叫</el-checkbox> -->
      </el-form-item>

      <el-form-item prop="ck_007_sys_setting_sp6_12">
        <el-checkbox v-model="query.ck_007_sys_setting_sp6_12">支付方式为预付卡已支付订单不允许跨站转派</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_sp6_15">
        <el-checkbox v-model="query.ck_007_sys_setting_sp6_15">订单不允许跨站转派</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_sp6_17">
        <el-checkbox v-model="query.ck_007_sys_setting_sp6_17">复检通过时需要拍照取证</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_sp6_19">
        <el-checkbox v-model="query.ck_007_sys_setting_sp6_19">报修下单时责任机构仅支持用户所属机构</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_sp6_20">
        <el-checkbox v-model="query.ck_007_sys_setting_sp6_20">报修单自动审核</el-checkbox>
      </el-form-item>

      <el-form-item class="config-item" prop="ck_007_sys_setting_sp6_26">
        <el-checkbox v-model="query.ck_007_sys_setting_sp6_26">启动安检隐患告知单</el-checkbox>
      </el-form-item>
      <div class="config-group">
        <el-form-item label="生效安检类型：">
          <el-select v-model="query.checkTypes_sp6_26" multiple placeholder="请选择">
            <el-option
              v-for="item in checkTypeMap"
              :key="item.value"
              :label="item.desc"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
      </div>
      <div class="config-group">
        <el-form-item label="生效隐患等级：">
          <el-select v-model="query.warnLevels_sp6_26" multiple placeholder="请选择">
            <el-option
              v-for="item in warnLevelMap"
              :key="item.value"
              :label="item.desc"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
      </div>

      <!-- <el-form-item prop="ck_007_sys_setting_5_12">
        <el-checkbox v-model="query.ck_007_sys_setting_5_12">开启电子合同签署</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_5_13">
        <el-checkbox v-model="query.ck_007_sys_setting_5_13">开启营业执照验证</el-checkbox>
      </el-form-item> -->
      <!-- <el-form-item prop="chipSupport" label="芯片识读支持">
        <el-select v-model="query.chipSupport" size="mini">
          <el-option :value="1" label="多立恒" />
          <el-option :value="2" label="华申" />
          <el-option :value="3" label="祥康" />
        </el-select>
      </el-form-item>
    </el-form>
    <table class="table" style="margin-left: 10px;" align="left">
      <thead align="center">
        <td>操作</td>
        <td>开启扫瓶</td>
        <td>启用异常校验</td>
        <td>开启库存校验</td>
      </thead>
      <tbody align="center">
        <tr>
          <td>配送领瓶</td>
          <td>
            <el-checkbox :checked="true" disabled />
          </td>
          <td>
            <el-checkbox v-model="query.ck_007_sys_setting_5_0" />
          </td>
          <td>--</td>
        </tr>
        <tr>
          <td>配送</td>
          <td>
            <el-checkbox :checked="true" disabled />
          </td>
          <td>
            <el-checkbox v-model="query.ck_007_sys_setting_5_1" />
          </td>
          <td>--</td>
        </tr>
        <tr>
          <td>配送还瓶</td>
          <td>
            <el-checkbox :checked="true" disabled />
          </td>
          <td>
            <el-checkbox v-model="query.ck_007_sys_setting_5_2" />
          </td>
          <td>--</td>
        </tr>
        <tr>
          <td>欠瓶还瓶</td>
          <td>
            <el-checkbox v-model="query.ck_007_sys_setting_5_3" />
          </td>
          <td>
            <el-checkbox v-model="query.ck_007_sys_setting_5_4" />
          </td>
          <td>--</td>
        </tr>
        <tr>
          <td>退瓶</td>
          <td>
            <el-checkbox :checked="true" disabled />
          </td>
          <td>
            <el-checkbox v-model="query.ck_007_sys_setting_5_5" />
          </td>
          <td>--</td>
        </tr>
        <tr>
          <td>回收商品扫瓶</td>
          <td rowspan="2">
            <el-checkbox v-model="query.ck_007_sys_setting_5_6" />
          </td>
          <td>
            <el-checkbox v-model="query.ck_007_sys_setting_5_7" />
          </td>
          <td>--</td>
        </tr>
        <tr>
          <td>置换商品扫瓶</td>
          <td>
            <el-checkbox v-model="query.ck_007_sys_setting_5_8" />
          </td>
          <td>--</td>
        </tr>
        <tr>
          <td>装车扫瓶</td>
          <td rowspan="2">
            <el-checkbox v-model="query.ck_007_sys_setting_5_9" />
          </td>
          <td>
            <el-checkbox v-model="query.ck_007_sys_setting_5_10" />
          </td>
          <td rowspan="2">
            <el-checkbox v-model="query.ck_007_sys_setting_5_14" />
          </td>
        </tr>
        <tr>
          <td>卸车扫瓶</td>
          <td>
            <el-checkbox v-model="query.ck_007_sys_setting_5_11" />
          </td>
        </tr>
      </tbody>
    </table> -->
    </el-form></div>
</template>

<script>
  import { mapGetters } from 'vuex'
  import { queryRiskTrackMap } from '@/api'

  export default {
    name: 'BasicTab',
    data() {
      return {
        query: {
          pbxURL: '',
          maxFloor: '',
          sp1: false,
          fee1: '',
          chipSupport: 1,
          ck_007_sys_setting_sp5_15: false,
          ck_007_sys_setting_1_22: false,
          ck_007_sys_setting_1_28: false,
          ck_007_sys_setting_2_16: false,
          ck_007_sys_setting_2_24: false,
          ck_007_sys_setting_2_26: false,
          ck_007_sys_setting_3_8: false,
          ck_007_sys_setting_3_14: false,
          ck_007_sys_setting_3_18: false,
          ck_007_sys_setting_3_19: false,
          ck_007_sys_setting_3_10: false,
          ck_007_sys_setting_3_31: false,
          ck_007_sys_setting_sp4_1: false,
          ck_007_sys_setting_sp4_2: false,
          ck_007_sys_setting_5_12: false,
          ck_007_sys_setting_5_13: false,
          ck_007_sys_setting_5_0: false,
          ck_007_sys_setting_5_1: false,
          ck_007_sys_setting_5_2: false,
          ck_007_sys_setting_5_3: false,
          ck_007_sys_setting_5_4: false,
          ck_007_sys_setting_5_5: false,
          ck_007_sys_setting_5_6: false,
          ck_007_sys_setting_5_7: false,
          ck_007_sys_setting_5_8: false,
          ck_007_sys_setting_5_9: false,
          ck_007_sys_setting_5_10: false,
          ck_007_sys_setting_5_14: false,
          ck_007_sys_setting_5_11: false,
          ck_007_sys_setting_sp4_22: false,
          ck_007_sys_setting_sp4_21: false,
          ck_007_sys_setting_sp6_9: false,
          onlineAudit: null,
          offlineAudit: null,
          ck_007_sys_setting_1_25: false,
          depAuditChannel: [],
          ck_007_sys_setting_sp6_12: false,
          ck_007_sys_setting_sp6_15: false,
          ck_007_sys_setting_sp6_17: false,
          ck_007_sys_setting_sp6_18: false,
          ck_007_sys_setting_sp6_19: false,
          ck_007_sys_setting_sp6_20: false,
          ck_007_sys_setting_sp6_26: false,
          checkTypes_sp6_26: [],
          warnLevels_sp6_26: []
        },
        rules: {
          // pbxURL: [{ required: true, message: '请输入', trigger: 'change' }]
        },
        channelOptions: [
          {
            desc: '公众号/小程序',
            value: 1
          },
          {
            desc: '运气到家',
            value: 2
          },
          {
            desc: '企业端',
            value: 4
          }
        ],
        checkTypeMap: [
          { value: 1, desc: '随单安检', key: 'SD' },
          { value: 2, desc: '定期安检', key: 'JH' }
        ],
        warnLevelMap: []
      }
    },
    computed: {
      ...mapGetters([
        'corpSettingData', 'userInfo'
      ])
    },
    created() {
      this.init()
      this.getdanger()
    },
    methods: {
      init() {
        if (this.corpSettingData) {
          this.query.pbxURL = this.corpSettingData.pbxURL
          this.query.ck_007_sys_setting_sp5_15 = !!(this.corpSettingData.sp5 >> 15 & 0x01)
          this.query.ck_007_sys_setting_1_1 = !!(this.corpSettingData.sp1 >> 1 & 0x01)
          this.query.ck_007_sys_setting_1_22 = !!(this.corpSettingData.sp1 >> 22 & 0x01)
          this.query.ck_007_sys_setting_1_28 = !!(this.corpSettingData.sp1 >> 28 & 0x01)
          this.query.ck_007_sys_setting_2_16 = !!(this.corpSettingData.sp2 >> 16 & 0x01)
          this.query.ck_007_sys_setting_2_24 = !!(this.corpSettingData.sp2 >> 24 & 0x01)
          this.query.ck_007_sys_setting_2_26 = !!(this.corpSettingData.sp2 >> 26 & 0x01)
          this.query.ck_007_sys_setting_3_8 = !!(this.corpSettingData.sp3 >> 8 & 0x01)
          this.query.ck_007_sys_setting_3_14 = !!(this.corpSettingData.sp3 >> 14 & 0x01)
          this.query.ck_007_sys_setting_3_18 = !!(this.corpSettingData.sp3 >> 18 & 0x01)
          this.query.ck_007_sys_setting_3_19 = !!(this.corpSettingData.sp3 >> 19 & 0x01)
          this.query.ck_007_sys_setting_3_10 = !!(this.corpSettingData.sp3 >> 10 & 0x01)
          this.query.ck_007_sys_setting_3_31 = !!(this.corpSettingData.sp3 >> 31 & 0x01)
          this.query.ck_007_sys_setting_sp4_1 = !!(this.corpSettingData.sp4 >> 1 & 0x01)
          this.query.ck_007_sys_setting_sp4_2 = !!(this.corpSettingData.sp4 >> 2 & 0x01)
          this.query.ck_007_sys_setting_5_12 = !!(this.corpSettingData.sp5 >> 12 & 0x01)
          this.query.ck_007_sys_setting_5_13 = !!(this.corpSettingData.sp5 >> 13 & 0x01)
          this.query.ck_007_sys_setting_5_0 = !!(this.corpSettingData.sp5 & 0x01)
          this.query.ck_007_sys_setting_5_1 = !!(this.corpSettingData.sp5 >> 1 & 0x01)
          this.query.ck_007_sys_setting_5_2 = !!(this.corpSettingData.sp5 >> 2 & 0x01)
          this.query.ck_007_sys_setting_5_3 = !!(this.corpSettingData.sp5 >> 3 & 0x01)
          this.query.ck_007_sys_setting_5_4 = !!(this.corpSettingData.sp5 >> 4 & 0x01)
          this.query.ck_007_sys_setting_5_5 = !!(this.corpSettingData.sp5 >> 5 & 0x01)
          this.query.ck_007_sys_setting_5_6 = !!(this.corpSettingData.sp5 >> 6 & 0x01)
          this.query.ck_007_sys_setting_5_7 = !!(this.corpSettingData.sp5 >> 7 & 0x01)
          this.query.ck_007_sys_setting_5_8 = !!(this.corpSettingData.sp5 >> 8 & 0x01)
          this.query.ck_007_sys_setting_5_9 = !!(this.corpSettingData.sp5 >> 9 & 0x01)
          this.query.ck_007_sys_setting_5_10 = !!(this.corpSettingData.sp5 >> 10 & 0x01)
          this.query.ck_007_sys_setting_5_14 = !!(this.corpSettingData.sp5 >> 14 & 0x01)
          this.query.ck_007_sys_setting_5_11 = !!(this.corpSettingData.sp5 >> 11 & 0x01)
          this.query.ck_007_sys_setting_sp4_22 = !!(this.corpSettingData.sp4 >> 22 & 0x01)
          this.query.ck_007_sys_setting_sp4_21 = !!(this.corpSettingData.sp4 >> 21 & 0x01)
          this.query.ck_007_sys_setting_1_25 = !!(this.corpSettingData.sp1 >> 25 & 0x01)
          this.query.fee1 = this.corpSettingData.fee1 * 0.01
          this.query.onlineAudit = this.corpSettingData.onlineAudit
          this.query.offlineAudit = this.corpSettingData.offlineAudit
          this.query.ck_007_sys_setting_sp6_9 = !!(this.corpSettingData.sp6 >> 9 & 0x01)
          this.query.ck_007_sys_setting_sp6_12 = !!(this.corpSettingData.sp6 >> 12 & 0x01)
          this.query.ck_007_sys_setting_sp6_15 = !!(this.corpSettingData.sp6 >> 15 & 0x01)
          this.query.ck_007_sys_setting_sp6_17 = !!(this.corpSettingData.sp6 >> 17 & 0x01)
          this.query.ck_007_sys_setting_sp6_18 = !!(this.corpSettingData.sp6 >> 18 & 0x01)
          this.query.ck_007_sys_setting_sp6_19 = !!(this.corpSettingData.sp6 >> 19 & 0x01)
          this.query.ck_007_sys_setting_sp6_20 = !!(this.corpSettingData.sp6 >> 20 & 0x01)
          this.query.ck_007_sys_setting_sp6_26 = !!(this.corpSettingData.sp6 >> 26 & 0x01)
          const checkTypes = this.corpSettingData.checkTypes ? this.corpSettingData.checkTypes.split(',') : []
          const warnLevels = this.corpSettingData.warnLevels ? this.corpSettingData.warnLevels.split(',') : []
          this.query.checkTypes_sp6_26 = checkTypes.map((item) => (Number(item)))
          this.query.warnLevels_sp6_26 = warnLevels.map((item) => (Number(item)))
          // 芯片识读支持设置
          if ((this.corpSettingData.sp4 >> 22 & 0x01) > 0) {
            this.query.sp4 = 2
          }
          if ((this.corpSettingData.sp4 >> 23 & 0x01) > 0) {
            this.query.sp4 = 3
          }
          if (this.corpSettingData.depAuditChannel > 0) {
            this.channelOptions.forEach(channel => {
              const checked = ((this.corpSettingData.depAuditChannel & channel.value) === channel.value)
              channel.checked = checked
            })
          }
          this.channelOptions.forEach(i => {
            if (i.checked) this.query.depAuditChannel.push(i.value)
          })
        }
      },
      // 查询隐患等级
      async getdanger() {
        // presetDicQueryList
        const res = await queryRiskTrackMap()
        const data = JSON.parse(res.data.warnLevel) // 隐患等级
        if (data) {
          console.log('data', data)
          const filterData = data.filter(item => item.keyVal !== 0) // 过滤无隐患选项
          this.warnLevelMap = filterData.map(item => {
            return {
              value: item.keyVal,
              desc: item.keyName
            }
          })
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
.form {
  .el-form-item {
    margin-bottom: 0;
  }
  /deep/.el-form-item__content {
    line-height: 40px !important;
  }
}
.table {
  border-collapse: collapse;
  td {
    padding: 5px 10px;
    color: #606266;
    border: 1px solid #dedede;
  }
}
.config-group {
  padding-left: 12px;
  margin-bottom: 10px;
  /deep/ .el-select {
    width: 30%;
    min-width: 300px;
  }
}
</style>
